<template>
  <!-- 头部部分 -->
  <header class="header">
    <h1>todos</h1>
    <input
      class="new-todo"
      placeholder="请输入任务名称"
      autofocus
      v-model.trim="username"
      @keyup.enter="addItem($event.target.value)"
    />
  </header>
</template>

<script>
export default {
  data() {
    return {
      username: "",
    };
  },
  methods: {
    addItem(value) {
      if (this.username === "") {
        alert("输入框不能为空");
        return;
      } else {
        this.$emit("add", value);
      }
      this.username = "";
    },
  },
};
</script>

<style></style>